home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / smail-3.1.28 / util / mkpath.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  1992-07-11  |  3.8 KB  |  147 lines

  1. #! /bin/sh
  2. # @(#)util/mkpath.sh    1.6 7/11/92 11:40:14
  3. #
  4. # mkpath - make a pathalias output file
  5. #
  6. #    Copyright (C) 1988 Ronald S. Karr and Landon Curt Noll
  7. #    Copyright (C) 1992 Ronald S. Karr
  8. #
  9. # See the file COPYING, distributed with smail, for restriction
  10. # and warranty information.
  11.  
  12. # Usage:    
  13. #    mkpath [-v] [-V] [-x] [-e] [-n] [-t trace] [path_config]
  14. #
  15. #    -v        verbose mode for mkpath, execution block commands
  16. #            are executed with the sh(1) -v flag
  17. #    -V        pathalias(8) runs with '-v' verbose mode
  18. #    -x         execution block commands are executed with the
  19. #            sh(1) '-x' option.
  20. #    -e        tries to get mkpath to stop when it encounters a
  21. #            syntax error, and the internal sh(1) to stop when
  22. #            a top level command exits with a non-zero status.
  23. #    -n        disables the execution of any sh(1) commands
  24. #            useful with the '-v' and disables '-x', '-e', '-V', '-t'
  25. #    -t trace    all input of pathalias(8) is to be copied into
  26. #            the file 'trace'.
  27. #    path_config     pathalia's configuration file, '-' => stdin,
  28. #            or $LIB_DIR/maps/mkpath.conf by default
  29. #
  30. # If '-V' and '-t' are both used, '-V' must be before '-t'.
  31.  
  32.  
  33. # base directory for smail library/utility
  34. #
  35. # These directories should be owned by root, and only writeable by root
  36. #
  37. LIB_DIR="X_LIB_DIR_X"
  38. UTIL_BIN_DIR="X_UTIL_BIN_DIR_X"
  39. TMPDIR="X_TMP_DIR_X"
  40. MAPDIR="$LIB_DIR/maps"
  41.  
  42. # standard locations
  43. #
  44. PATHALIAS=$UTIL_BIN_DIR/pathalias
  45. DCASEHOST=$UTIL_BIN_DIR/dcasehost
  46. AWKFILE=$UTIL_BIN_DIR/mkpath.awk
  47. GLEEM=$UTIL_BIN_DIR/gleem
  48. GETOPT=$UTIL_BIN_DIR/getopt
  49. SORT=sort
  50. PATH="X_UTIL_PATH_X:X_SECURE_PATH_X"; export PATH
  51.  
  52. # parse args - need a public domain getopt command - XXX
  53. #
  54. PROG=$0
  55. USAGE="$PROG: usage: $PROG [-v] [-V] [-x] [-e] [-n] [-t trace] [path_config]"
  56. set -- `$GETOPT -n $PROG -q vVxent: $*`
  57. if [ "$?" -ne 0 ]; then
  58.     echo "$USAGE" 1>&2
  59.     exit 1
  60. fi
  61. SHELL_ARGS="-"
  62. ERR=0
  63. TEE_FILE=
  64. PWD=`pwd`
  65. for i in $*; do
  66.     case $i in
  67.     -v)    SHELL_ARGS="$SHELL_ARGS"v; shift;;
  68.     -V)    PATHALIAS="$PATHALIAS -v"; shift;;
  69.     -x)    SHELL_ARGS="$SHELL_ARGS"x; shift;;
  70.     -e)    SHELL_ARGS="$SHELL_ARGS"e; ERR=1; shift;;
  71.     -n)    SHELL_ARGS="$SHELL_ARGS"n; shift;;
  72.     -t) if [ -z "$TEE_FILE" ]; then
  73.         TEE_FILE="$2"; PATHALIAS="tee -a $TEE_FILE | $PATHALIAS";
  74.     fi; shift 2;;
  75.     --)    shift; break;;
  76.     esac
  77. done
  78. # determine the path.conf config file
  79. if [ "$#" -gt 1 ]; then
  80.     echo "$USAGE"
  81.     exit 4
  82. elif [ "$#" -eq 1 ]; then
  83.     CONFIG="$1"
  84. else
  85.     CONFIG=
  86. fi
  87.  
  88. # verify that we can read the config file
  89. # determine the initial directory
  90. #
  91. if [ "$CONFIG" = "-" ]; then
  92.     CD="$PWD"
  93.     CONFIG="mkpath_stdin"
  94.     CONF=""
  95. elif [ -z "$CONFIG" ]; then
  96.     CD="$MAPDIR"
  97.     cd "$CD"
  98.     CD=`pwd`
  99.     CONFIG="$MAPDIR"/mkpath.conf
  100.     CONF="$CONFIG"
  101. elif [ -r "$CONFIG" ]; then
  102.     if [ "`expr $CONFIG : '\\/'`" -eq 0 ]; then
  103.     CD=`pwd`
  104.     else
  105.         CD=`echo "$CONFIG" | sed 's,^\(.*\)/[^/][^/]*$,\1,'`
  106.     cd "$CD"
  107.     CD=`pwd`
  108.     fi
  109.     CONF="$CONFIG"
  110. else
  111.     echo "$PROG: can not read $CONFIG" 1>&2
  112.     exit 5
  113. fi
  114.  
  115. # special action commands
  116. #
  117. # args to run pathalias, switch fields and sort for the pathsort command
  118. PATHSORT="$PATHALIAS -i -D|$DCASEHOST|$SORT -T $TMPDIR"
  119.  
  120. # export vars needed for the sub-shell
  121. #
  122.  
  123. # process the config file
  124. #
  125. trap "rm -f $TMPDIR/stm*;exit 1" 1 2 3 15
  126. if [ "$TEE_FILE" ]; then
  127.     cat /dev/null > $TEE_FILE
  128. fi
  129. # strip input of #comments, run it thru awk and into the shell
  130. (echo "#! /bin/sh $SHELL_ARGS"
  131.  echo "PROG=\"$PROG\""
  132.  echo "PWD=\"$PWD\""
  133.  echo "CD=\"$CD\""
  134.  echo "CWD=\"$CD\""
  135.  echo "ERR=\"$ERR\""
  136.  echo "PATH=\"$PATH\""
  137.  echo "GLEEM=\"$GLEEM\""
  138.  echo "PATHALIAS=\"$PATHALIAS\""
  139.  echo "PATHSORT=\"$PATHSORT\""
  140.  echo "export PROG PWD CD CWD ERR PATH GLEEM PATHALIAS PATHSORT"
  141.  if [ -z "$CONF" ]; then
  142.     sed -e 's/[     ]*#.*$//' -e 's/^[     ]*//'
  143.  else    
  144.     sed -e 's/[     ]*#.*$//' -e 's/^[     ]*//' < "$CONFIG"
  145.  fi | awk -f "$AWKFILE" ERR="$ERR" PROG="$PROG" - ) | /bin/sh "$SHELL_ARGS"
  146. exit $?
  147.